This is a project I had about 6 weeks to work on with a group of 4 others, with me being assigned to code the entire game from the Health mechanics to combat. the software used was Unity mainly and Visual Studio for coding.
the parameters for this project was for it to be mostly completed within 6 weeks and the final product to be of medium fedelity prototype. The main theme of the game would have to be based around renewable energy with the group being able to decide the genre of the game and style. We were assigned into groups of 5-6 with set roles decided in a group descussion with me being assigned as the only coder to code the whole game from the ground up in a white box. at the end I ended up completing the base games mechanics but was left without assets so the final product was left with the white box. however most of the coding done was from myself with only some help from acceessable youtube tutorials to get an understanding of what I needed to do. Click the photo to download and have a go at the game!
at the start gets the players rigidbody for jumping and sets the current speed to the defult speed veriable also in updates it is always checking the coroutine to see if it should run based off of if statements and also looks out for a bool that will stop the moveplayer coroutine if true for a set amount of time.
Checking for a collision with the players capsule collider and if whatever the player collided withs tag is "Hazard" the if statement will run setting Ouch to =true which will stop the player and enemy movement temporarily accourding to the coroutine(stop) which will run for 0.5 seconds then set ouch to false allowing everything to move again. also the if statement moves the player left by a certain amount to stop staying in the collider.
the (Flip) routine flips the player model around depending on which direction it is moving in by transforming the models scale by times -1 which either makes it negative making it face a certain way or a negative times a negative makes a posative making it face the opposite direction. with the ontriggerstay it is used to change the players speed as long as it is staying in smog and isnt under a light.
The code for the basic movement of the player with it getting the Horizontal input for left and right movement instead of assigning each key to a certain direction and using the asigned speed times by the Time.deltatime to figure out how fast the character should be moving with Time.deltatime being used so the character wouldnt move faster or slower depending on framerate. with jumping it was a bit more complicated with me having to apply a force to the player to make the jump somewhat more relaistic with an arc, and with only an impule force as to only apply the force once momentarily to stop the player from flying away also there is a ground check on the if statment as to not let the player jump continuously. the if statements for the dashing require 2 buttons to be pressed or held down together and that canDash = true as to stop back to back dashing. the if statements for flipping work by detecting if the HorizontalInput is posative or negative as going left is -1 and right is 1 which then lets the program know which way they should be flipped.
This script is to controll the ammo for the players gun as the player actually has 2 different gun for shooting straight ahead and also shooting down so to properly have a single ammo counter instead of one for each gun I needed a seperate script for them. this script just sets current ammo to the max ammo at the start and takes away 1 every time the gun is shot and for reloading the currentammo gets reset and it starts a coroutine where you cannot shoot again until it is over
This script applies to the bullets itself and tells the bullet when it needs to be destroyed either when the life runs out which is 1.5f or when it hits something tagged "Hazard"
The lightControl script allows the player to heal themselves under it with the assigned healthvalue within the script once whenever the player is in the trigger "light" it also sets InSmog false as to restore the players movement speed. the else if is for if the player is already at max health it doesnt run the code.
the first piece of code is if ouch from playermovement = true then the enemy this is attached to will also stop moving. when the enemy reaches the max position it switches the Turn bool to true and also flips the model with the same code as with the player. when turn is true it tells the code to run the coroutine moveRight and vice versa when turn is false.
The moveRight and moveLeft routines simply make the enemy constantly move in the set direction at the speed set in the veriables beforehand until they reach the max or min position where it activates the other routine and flips the character model.
The script for the second enemyController starts with getting the players position through looking at the transform of what ever is tagged "player" and also getting its own rigidbody for later code enabling jumping then theres also the if ouch true code snippet to stop the enemy if the player has been hit as not to instantly kill the player in some scenarios. the code then contstantly gets the distance from the player and also from a box that the player can move around by comparing its position and the player / box's position. then the next if statement requires the player's x position to be more thank its own then it will execute the code which makes it first turn to face right by once again flipping the scalling of the model by negative 1 and makes the enemy move in that direction towards the player. same applys for the else if but for moving left. there is also an activation distance that is set at the start amd if the distance from the player is more than it the code stops the enemy from moving and only when the player walks into the activation radius the enemy can start to move to attack them.
theres also similar code for the distance from the bos however in this case if the box is close enought to the enemy it can jump over it as before hand they were easy to deal with as they could get stuck behind the box the if statements require a ground check before it can execute the jump coroutine as otherwise the enemy would keep jumping constantly until the box was out of the activation radius. then theres another methode to stop the enemy from moving once the player is hit by detecting if iit has collided with something tagged with "Player" and when it does the coroutine (Wait) starts where it waits for 1 second using an ienumerator.
the Groundcheck is coded the same as with the player having a empty object bellow the enemy model checking for a collision with a layer called "ground" and the jump uses the rigidbody of the enemy model we got earlier and applies force momentarily upwards like how it was also done in the player movement scripts.
The code for the EnemyControl3 script was mostly all done by my lecturer Robert Blofield in his Computer Game Design Principles class during week 10 of semester 1 where we got taught state machines and step by step copied most of the code while fixing some intentional errors that were designed to challenge us stats work by setting what will happen when running the state like for example in the code for in enemystate.Firing when in the state it runs code to fire projectiles at the player where as in the void update you can set if statement for conditions when to switch states this is more advanced and efficiant than using multiple bools to do the same thing. the only code within the script that was not done by Rob would be the player flipping which was the same code as used in my other scripts to flip player models as the 3D rotation using quaternion slerp that was provided did not work with my game.
The barrel controls makes it so when it is applied to something with the tag "barrel" and gets hit by something with the tag "Bullet" it destroys the barrel and in its position it instantiates a key prefab with all the code it needs.
this code is for the camera to follow the player in a smooth way that doesnt hurt the eyes when there is sudden and fast movement the mathf.Clamp keeps the camera from going out of bounds and the targetPosition adds and offset as to trail the player slightly behind and then to actually follow the player it has a transfrom.position with vector3 smoothdamp so the camera is smooth and smoothtime so the camera doesnt snap to the player
This image is the combanation of 2 scripts both the hatch control and glass break control. for the hatch control when it collides with something tagged "rock" it will be destroyed. and the hatch also gets destroyed by it has to meet the requirements of both it being the player and HasKey must equal true, when the code is run HasKey gets set false so another key can be picked up and also so the player can run through the levels without trying to find the key.